package com.zly.entity;

import java.util.List;

public class DistanceCalculateResult {
    //参数列表“距离计算”结果

    public static final int WRAP_DISTANCE = 1;
    public static final int OBJECT_DISTANCE = 5;
    public static final int MIN_DISTANCE = 0;
    public static final int MAX_DISTANCE = Integer.MAX_VALUE;

    private static DistanceCalculateResult WORST_RESULT = null;
    private static DistanceCalculateResult BEST_RESULT = null;

    //距离
    private final int distance;

    //存在两参数列表对应的两参数一个为基本类型数组，另一个为其包装类型数组的现象
    private final boolean existArrayWrap;

    private final List<Integer> wrapIndexList;

    public static DistanceCalculateResult worstResult() {
        if(WORST_RESULT == null){
            WORST_RESULT = new DistanceCalculateResult(MAX_DISTANCE);
        }
        return WORST_RESULT;
    }

    public static DistanceCalculateResult bestResult() {
        if(BEST_RESULT == null){
            BEST_RESULT = new DistanceCalculateResult(MIN_DISTANCE);
        }
        return BEST_RESULT;
    }

    //构造
    public DistanceCalculateResult(int distance, List<Integer> wrapIndexList) {
        this.distance = distance;
        if(wrapIndexList == null || wrapIndexList.isEmpty()){
            this.wrapIndexList = null;
            this.existArrayWrap = false;
        }else{
            this.wrapIndexList = wrapIndexList;
            this.existArrayWrap = true;
        }
    }
    public DistanceCalculateResult(int distance) {
        this(distance,null);
    }

    //getter
    public int distance() {
        return distance;
    }
    public boolean existArrayWrap() {
        return existArrayWrap;
    }
    public List<Integer> wrapIndexList() {
        return wrapIndexList;
    }

    //
    public boolean betterThan(DistanceCalculateResult other) {
        return distance < other.distance;
    }

    public boolean worseThan(DistanceCalculateResult other) {
        return distance > other.distance;
    }

}
